﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimeFactorization
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            p.calculate();
        }

        public void calculate()
        {
            while (true)
            {
                Console.WriteLine("素数分解（输入一个数字）（输入“exit”退出）:");
                string numstr = Console.ReadLine();
                if (numstr.Equals("exit"))
                    break;
                try
                {
                    bool isfirst = true;
                    int num = int.Parse(numstr);
                    if (num <= 1)
                        throw new Exception();
                    int factor = 2;
                    while (factor <= num)
                    {
                        if (num % factor == 0)
                        {
                            if (isfirst)
                            {
                                Console.Write(""+num+" = " + factor);
                                isfirst = false;
                            }
                            else
                                Console.Write(" * " + factor);
                            num /= factor;
                        }
                        else
                            factor++;
                    }
                    Console.Write("\n");
                }catch (Exception) { }
            }
        }
    }
}
